package com.example.demo2.action;

import com.example.demo2.biz.employeeBiz;
import com.example.demo2.pojo.employee;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/userserver")
public class employeeAction {


        @Autowired
        private  employeeBiz employeebiz;

        @GetMapping("/user/{id}")
        public employee  list(@PathVariable Integer id){


            return employeebiz.list(id);
        }

        @GetMapping("/selectall")
        public List<employee> selectall(){
            return  employeebiz.selectall();
        }

        @GetMapping("/deleteByid/{id}")
        public Integer deleteByid(@PathVariable Integer id){
            return  employeebiz.deleteByid(id);
        }
        @GetMapping("/inserts")
        public Integer inserts(employee employee){
            return  employeebiz.inserts(employee);
        }

        @GetMapping("/updateByid")
        public Integer updateByid(employee employee){
            return employeebiz.updateByid(employee);
        }


    public static void main(String[] args) {
        try {
            List<String> warnings = new ArrayList<String>();
            boolean overwrite = true;
            File configFile = new File("mbg.xml");
            ConfigurationParser cp = new ConfigurationParser(warnings);
            Configuration config = cp.parseConfiguration(configFile);
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
            myBatisGenerator.generate(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
